package com.ruoyi.training.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.training.domain.Curriculum;
import com.ruoyi.training.mapper.CurriculumMapper;
import com.ruoyi.training.service.ICurriculumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 培训课程管理Service业务层处理
 *
 * @author wng
 * @date 2024-08-04
 */
@Service
public class CurriculumServiceImpl implements ICurriculumService {
    @Resource
    private CurriculumMapper curriculumMapper;

    /**
     * 查询培训课程管理
     *
     * @param id 培训课程管理主键
     * @return 培训课程管理
     */
    @Override
    public Curriculum selectCurriculumById(Long id) {
        return curriculumMapper.selectCurriculumById(id);
    }

    /**
     * 查询培训课程管理列表
     *
     * @param curriculum 培训课程管理
     * @return 培训课程管理
     */
    @Override
    public List<Curriculum> selectCurriculumList(Curriculum curriculum) {
        if (curriculum.getParams() != null) {
            if (curriculum.getParams().containsKey("createTimeStart") && curriculum.getParams().containsKey("createTimeEnd")) {
                if (curriculum.getParams().get("createTimeStart") != null && !"".equals(curriculum.getParams().get("createTimeStart"))
                        && curriculum.getParams().get("createTimeEnd") != null && !"".equals(curriculum.getParams().get("createTimeEnd"))) {
                    curriculum.getParams().put("createTimeStart", curriculum.getParams().get("createTimeStart") + " 00:00:00");
                    curriculum.getParams().put("createTimeEnd", curriculum.getParams().get("createTimeEnd") + " 23:59:59");
                }

            }
        }
        return curriculumMapper.selectCurriculumList(curriculum);
    }

    /**
     * 新增培训课程管理
     *
     * @param curriculum 培训课程管理
     * @return 结果
     */
    @Override
    public int insertCurriculum(Curriculum curriculum) {
        curriculum.setCreateTime(DateUtils.getNowDate());
        return curriculumMapper.insertCurriculum(curriculum);
    }

    /**
     * 修改培训课程管理
     *
     * @param curriculum 培训课程管理
     * @return 结果
     */
    @Override
    public int updateCurriculum(Curriculum curriculum) {
        curriculum.setUpdateTime(DateUtils.getNowDate());
        return curriculumMapper.updateCurriculum(curriculum);
    }

    /**
     * 批量删除培训课程管理
     *
     * @param ids 需要删除的培训课程管理主键
     * @return 结果
     */
    @Override
    public int deleteCurriculumByIds(Long[] ids) {
        return curriculumMapper.deleteCurriculumByIds(ids);
    }

    /**
     * 删除培训课程管理信息
     *
     * @param id 培训课程管理主键
     * @return 结果
     */
    @Override
    public int deleteCurriculumById(Long id) {
        return curriculumMapper.deleteCurriculumById(id);
    }
}
